package inline;

import android.os.Looper;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class CrashDemo {
    public static void a(long arg2) {
        if (arg2 <= 0) {
            throw new IllegalArgumentException("duration not be minus");
        }
        try {
            TimeUnit.MILLISECONDS.sleep(arg2);
        } catch (InterruptedException v0) {
            v0.printStackTrace();
        }
    }

    public static JSONObject a(boolean arg15) throws JSONException {
        JSONObject v0_4;
        int v0_3;
        Map v0 = Thread.getAllStackTraces();
        if (v0 != null && v0.size() > 0) {
            JSONObject v5 = new JSONObject();
            v5.put("thread_number", v0.size());
            JSONArray v8 = new JSONArray();
            Iterator v9 = v0.entrySet().iterator();
            int v1 = 0;
            int v4;
            for (v4 = 0; v9.hasNext(); v4 = v0_3) {
                Object v0_1 = v9.next();
                int v3 = v1 + 1;
                long v10 = ((long) v3);
                long v6 = arg15 ? 500 : 5;
                if (v10 > v6) {
                    break;
                }

                JSONObject v7 = new JSONObject();
                StringBuilder v10_1 = new StringBuilder();
                StackTraceElement[] v1_1 = (StackTraceElement[]) ((Map.Entry) v0_1).getValue();
                int v11 = v1_1.length;
                int v6_1;
                for (v6_1 = 0; v6_1 < v11; ++v6_1) {
                    StackTraceElement v12 = v1_1[v6_1];
                    if (v10_1.length() > 15000) {
                        break;
                    }

                    v10_1.append("  at " + v12.toString()).append("\n");
                }

                try {
                    if (((Thread) ((Map.Entry) v0_1).getKey()).getName().equalsIgnoreCase("main")) {
                        v5.put("mainStackFromTrace", v10_1.toString());
                        v4 = 1;
                    }

                    v7.put("id", ((Thread) ((Map.Entry) v0_1).getKey()).getId());
                    v7.put("name", ((Thread) ((Map.Entry) v0_1).getKey()).getName());
                    v7.put("stack", v10_1.toString());
                    v0_3 = v4;
                } catch (JSONException v0_2) {
                    JSONException v1_2 = v0_2;
                    v0_3 = v4;
                    v1_2.printStackTrace();
                }

                v8.put(v7);
                v1 = v3;
            }

            if (v4 == 0) {
                v5.put("mainStackFromTrace", c());
            }

            v5.put("allThreadStack", v8);
            v5.put("anrTime", System.currentTimeMillis());
            v0_4 = v5;
        } else {
            v0_4 = null;
        }

        return v0_4;
    }

    private static String c() {
        StringBuilder v1 = new StringBuilder();
        StackTraceElement[] v2 = Looper.getMainLooper().getThread().getStackTrace();
        int v3 = v2.length;
        int v0;
        for (v0 = 0; v0 < v3; ++v0) {
            v1.append("  at " + v2[v0].getClassName()).append(".").append(v2[v0].getMethodName()).append("(").append(v2[v0].getFileName()).append(":").append(v2[v0].getLineNumber()).append(")\n");
        }

        return v1.toString();
    }
}
